package com.xxxx.server.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xxxx.server.pojo.Admin;
import com.xxxx.server.pojo.RespBean;
import com.xxxx.server.pojo.Sleashenhe;
import com.xxxx.server.pojo.Sleave;
import com.xxxx.server.service.ISleashenheService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;

/**
 * <p>
 * 学生离校审批 前端控制器
 * </p>
 *
 * @author zhoubin
 * @since 2022-06-28
 */
@RestController
@RequestMapping("/sleashenhe")
public class SleashenheController {

    @Autowired
    private ISleashenheService iSleashenheService;

    @ApiOperation(value = "更新辅导员审核")
    @PutMapping("/updateFdy")
    public RespBean updateFdySleaveSH(@RequestBody Sleashenhe sleashenhe){
        sleashenhe.setFudaoyuan(((Admin) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getName());
        if (iSleashenheService.updateById(sleashenhe)){
            return RespBean.success("更新成功！");
        }
        return RespBean.error("更新失败！");
    }

    @ApiOperation(value = "更新学院审核")
    @PutMapping("/updateXueyuan")
    public RespBean updateXueyuanSleaveSH(@RequestBody Sleashenhe sleashenhe){
        QueryWrapper queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id",sleashenhe.getId());
        Sleashenhe sleashenhe1 = iSleashenheService.getOne(queryWrapper);
        if(sleashenhe1.getFudaoyuan()==null || sleashenhe1.getFudaoyuan()==""){
            return RespBean.error("辅导员审核后才能进行审核！！");
        }
        if(sleashenhe1.getState1()==0){
            return RespBean.error("辅导员审核不同意无需继续审核！");
        }
        sleashenhe.setXueyuan(((Admin) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getName());
        if (iSleashenheService.updateById(sleashenhe)){
            return RespBean.success("更新成功！");
        }
        return RespBean.error("更新失败！");
    }

    @ApiOperation(value = "更新学校审核")
    @PutMapping("/updateXuexiao")
    public RespBean updateXuexiaoSleaveSH(@RequestBody Sleashenhe sleashenhe){
        QueryWrapper queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id",sleashenhe.getId());
        Sleashenhe sleashenhe1 = iSleashenheService.getOne(queryWrapper);
        if(sleashenhe1.getXueyuan()==null || sleashenhe1.getXueyuan()==""){
            return RespBean.error("学院管理员核后才能进行审核！！");
        }
        if(sleashenhe1.getState2()==0){
            return RespBean.error("学院审核不同意无需继续审核！");
        }
        sleashenhe.setXuexiao(((Admin) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getName());
        if (iSleashenheService.updateById(sleashenhe)){
            return RespBean.success("更新成功！");
        }
        return RespBean.error("更新失败！");
    }

}
